//GUIGraph generates three different graphs for the patient parameter

import java.awt.*;
import java.awt.event.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.data.*;
import org.jfree.data.time.Day;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.*;

import javax.swing.*;

public class GUIGraph extends JPanel{
    
    
    public GUIGraph(Patient p, int type)
    {
    	
    	
    	if(type == 0)
    	{
    		TimeSeries s1 = new TimeSeries(p.getFirstName()+ " " + p.getLastName());
            for(int i = 0; i < p.getSize(); i++)
            {
            	s1.add(new Day(p.getDayAt(i), p.getMonthAt(i),p.getYearAt(i)), p.getSugarAt(i));
            	
            }
            
            

    	// Add the series to your data set
            TimeSeriesCollection dataset = new TimeSeriesCollection();
            dataset.addSeries(s1);

    	// Generate the graph
    	   JFreeChart chart = ChartFactory.createTimeSeriesChart(
    	   "Blood Sugar", // Title
    	   "Time", // x-axis Label
    	   "mmol/L", // y-axis Label
    	   dataset, // Dataset
    	   true, // Show Legend
    	   true, // Use tooltips
    	   false // Configure chart to generate URLs?
    	   );
    	   
    	   JPanel jPanel1 = new JPanel();
       	   jPanel1.setLayout(new java.awt.BorderLayout());

       	   ChartPanel CP = new ChartPanel(chart);
       	   CP.setPreferredSize(new Dimension(500,500));
       	   

       	   jPanel1.add(CP,BorderLayout.CENTER);
       	   jPanel1.validate();
       	   
       	   this.add(jPanel1);
    	}
    	
    	
    	if(type == 1)
    	{
    		TimeSeries s1 = new TimeSeries(p.getFirstName()+ " " + p.getLastName());
            for(int i = 0; i < p.getSize(); i++)
            {
            	s1.add(new Day(p.getDayAt(i), p.getMonthAt(i),p.getYearAt(i)), p.getPressureAt(i));
            	
            }
            
            

    	// Add the series to your data set
            TimeSeriesCollection dataset = new TimeSeriesCollection();
            dataset.addSeries(s1);

    	// Generate the graph
    	   JFreeChart chart = ChartFactory.createTimeSeriesChart(
    	   "Blood Pressure", // Title
    	   "Time", // x-axis Label
    	   "mmHg", // y-axis Label
    	   dataset, // Dataset
    	   true, // Show Legend
    	   true, // Use tooltips
    	   false // Configure chart to generate URLs?
    	   );
    	   
    	   JPanel jPanel1 = new JPanel();
       	   jPanel1.setLayout(new java.awt.BorderLayout());

       	   ChartPanel CP = new ChartPanel(chart);
       	   CP.setPreferredSize(new Dimension(500,500));
       	   

       	   jPanel1.add(CP,BorderLayout.CENTER);
       	   jPanel1.validate();
       	   
       	   this.add(jPanel1);
    	}
    	
    	
    	if(type == 2)
    	{
    		TimeSeries s1 = new TimeSeries(p.getFirstName()+ " " + p.getLastName());
            for(int i = 0; i < p.getSize(); i++)
            {
            	s1.add(new Day(p.getDayAt(i), p.getMonthAt(i),p.getYearAt(i)), p.getWeightAt(i));
            	
            }
            
            

    	// Add the series to your data set
            TimeSeriesCollection dataset = new TimeSeriesCollection();
            dataset.addSeries(s1);

    	// Generate the graph
    	   JFreeChart chart = ChartFactory.createTimeSeriesChart(
    	   "Weight", // Title
    	   "Time", // x-axis Label
    	   "Kg", // y-axis Label
    	   dataset, // Dataset
    	   true, // Show Legend
    	   true, // Use tooltips
    	   false // Configure chart to generate URLs?
    	   );
    	   
    	   JPanel jPanel1 = new JPanel();
       	   jPanel1.setLayout(new java.awt.BorderLayout());

       	   ChartPanel CP = new ChartPanel(chart);
       	   CP.setPreferredSize(new Dimension(500,500));
       	   

       	   jPanel1.add(CP,BorderLayout.CENTER);
       	   jPanel1.validate();
       	   
       	   this.add(jPanel1);
    	}
    	
    	
    
    }
}
